package com.acwing.partition4;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/9 10:44
 */
public class AC379捉迷藏 {

    private static final int N = 210;
    private static boolean[][] graph = new boolean[N][N];
    private static int[] match = new int[N];
    private static boolean[] st = new boolean[N];
    private static int n = 0, m = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            graph[a][b] = true;
        }
        //传递闭包
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    graph[i][j] |= graph[i][k] & graph[k][j];
                }
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            Arrays.fill(st, false);
            if (dfs(i)) ans++;
        }
        writer.write((n - ans) + "\n");
        writer.flush();
    }

    private static boolean dfs(int u) {
        for (int i = 1; i <= n; i++) {
            if (!graph[u][i] || st[i]) continue;
            st[i] = true;
            if (match[i] == 0 || dfs(match[i])) {
                match[i] = u;
                return true;
            }
        }
        return false;
    }
}
